﻿using System;

using System.Management.Automation;
using CrystalDecisions.Enterprise;

namespace BO.Management.PowerShell
{
    [Cmdlet(VerbsCommon.Get, "ObjectLimit", DefaultParameterSetName = CONNECT_SECWINAD)]
    public class GetObjectLimit : BaseActionObject<ContentGenericProvider, InfoObject>
    {

        public override ContentGenericProvider GetProvider()
        {
            return new ContentGenericProvider(this.LogonProvider);
        }


        /// <summary>
        /// Get the object limit
        /// </summary>
        /// <param name="boeObject"></param>
        public override void WorkWithSingleObject(InfoObject boeObject)
        {
            if (boeObject != null)
            {
                WriteVerbose(String.Format("Extract Default Limit for the Folder {0}", boeObject.Title));
                SecurityInfoProvider infoProvider = new SecurityInfoProvider();
                SecurityLimit limit = infoProvider.GetDefaultLimit(boeObject);
                if (limit == null)
                {
                    WriteVerbose(String.Format("No Default Limit exist for the Folder {0}", boeObject.Title));
                    Console.WriteLine(String.Format("No Default Limit exist for the Folder {0}", boeObject.Title));
                }
                else
                {
                    WriteVerbose(String.Format("Current Limit for the Folder {0} is {1}", boeObject.Title, limit.Value));
                    this.WriteObject(limit);
                }
            }
        }

    }
}
